package ooday1.home.Guessing;

import java.util.Random;
import java.util.Scanner;

public class Guessing {
//    2.完成Guessing猜数字———————————————————练习while自造死循环
    //
    public static void main(String[] args) {
        System.out.println("猜数字游戏开始");
        int num=num();
        guessing(num);

    }
    public static int num(){
        Random an=new Random();
        int num=an.nextInt(100);
        return num;
    }
    public static void guessing(int num){
        Scanner scn=new Scanner(System.in);
        int num1;
        while (true){
            System.out.println("请输入你要猜的数字");
            num1=scn.nextInt();
            if (num1>num()){
                System.out.println("数字大了");
            }
            else if(num1<num()){
                System.out.println("数字小了");
            }else{
                System.out.println("恭喜你猜对了");
                break;
            }
        }
    }
}
